<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>{$title}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__ADMIN_PUBLIC__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__ADMIN_PUBLIC__/style/admin.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-btn-group test-table-operate-btn" style="margin-bottom: 10px;">
                        <button class="layui-btn" data-type="addTel" id="add-rule"><i class="layui-icon"></i> 新增规则</button>
                    </div>
                    <table class="layui-hide" id="test-table-rule" lay-filter="test-table-rule"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="addRule">
    <form class="layui-form" action="" style="padding-top: 20px;">
        <div class="layui-form-item">
            <label class="layui-form-label">上级目录：</label>
            <div class="layui-input-inline" style="width: 350px;">
                <select name="pid" lay-verify="required" lay-search="">
                    <option value="0">顶级目录</option>
                    {volist name="autuTree" id="v"}
                        <option value="{$v.id}"><?php echo str_repeat('—', ($v['type']-1 )*2)?>{$v.title}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">权限名称：</label>
            <div class="layui-input-inline" style="width: 350px;">
                <input type="text" name="title" class="layui-input" placeholder="权限名称" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">资源路径：</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" class="layui-input" name="module"  placeholder="模块名">
            </div>
            <div class="layui-form-mid">/</div>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" class="layui-input" name="controller"  placeholder="控制器">
            </div>
            <div class="layui-form-mid">/</div>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" class="layui-input" name="action"  placeholder="操作方法">
            </div>
        </div>
        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">资源类型：</label>-->
            <!--<div class="layui-input-block">-->
                <!--<input type="radio" name="type" value="1" title="目录" checked="">-->
                <!--<input type="radio" name="type" value="2" title="菜单">-->
                <!--<input type="radio" name="type" value="3" title="按钮">-->
            <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">权限状态：</label>
            <div class="layui-input-inline">
                <input type="checkbox" checked="" name="status" lay-skin="switch" lay-text="启用|禁用">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="butClick">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="__ADMIN_PUBLIC__/layui/layui.js"></script>
<script>
    layui.config({
        base: '__ADMIN_PUBLIC__/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
        treetable:'treetable-lay/treetable'
    }).use(['index','table','form','layer','treetable'], function(){
        var $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;
        var table = layui.table;
        var treetable = layui.treetable;

        var ruleTable = function () {
            layer.load(2);
            treetable.render({
                treeColIndex: 1,
                treeSpid: 0,
                treeIdName: 'id',
                treePidName: 'pid',
                treeDefaultClose: false,
                treeLinkage: false,
                elem: '#test-table-rule'
                ,url: 'getAuthRuleTree'
                ,cellMinWidth: 150
                ,page: false
                ,cols: [[
                     {field:'id', title:'ID',align:'center'}
                    ,{field:'title', title:'权限名称', align:'left'}
                    ,{field:'name', title:'资源路径', align:'center'}
                    ,{field:'status', title:'状态', align:'center',templet:function (d) {
                        if (d.status == "0") {
                            return '<span class="layui-btn layui-btn-xs layui-btn-disabled">禁用</span>';
                        }else if (d.status == "1") {
                            return '<span class="layui-btn layui-btn-xs  layui-btn-normal">启用</span>';
                        }
                    }}
                    ,{field:'type', title:'资源类型',align:'center',templet:function (d) {
                        if (d.type == "1") {
                            return '<span class="layui-btn layui-btn-xs">目录</span>';
                        }else if (d.type == "2") {
                            return '<span class="layui-btn layui-btn-xs  layui-btn-warm">菜单</span>';
                        }else if (d.type == "3") {
                            return '<span class="layui-btn layui-btn-xs  layui-btn-primary">按钮</span>';
                        }
                    }}
                    ,{field:'create_time', title:'创建时间', width:200,align:'center'}
                    ,{field:'right', title:'操作', toolbar: '#barDemo',align:'center'}
                ]],
                done: function () {
                    layer.closeAll('loading');
                }
            });

        };
        ruleTable();


        var openHtml;
        $('#add-rule').on('click',function () {
            //页面层
            openHtml =  layer.open({
                type: 1,
                title:'新增规则',
                skin: 'layui-layer-rim', //加上边框
                area: ['700px', '450px'], //宽高
                content:$('#addRule').html()
            });
            form.render();
        });

        // 立即提交
        form.on('submit(butClick)',function (obj) {
            console.log(obj);
            var data = obj.field;
            $.post("addUserRule",{data},function (response) {
                console.log(response);
                if(response.code == 0){
                    layer.msg(response.msg,{icon:6,time:1000},function () {
                        layer.close(openHtml);
                        ruleTable();
                    });
                }else{
                    layer.msg(response.msg,{icon:5,anim: 6});
                }
            });
            return false;
        });

        // table.on('tool(test-table-rule)',function (obj) {
        //     console.log(obj);
        //
        // });
    });
</script>
</body>
</html>